//
//  ICMAppointmentRepairPartsTableViewCell.m
//  ICrEAM
//
//  Created by Cty on 2016/11/03.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMAppointmentRepairPartsTableViewCell.h"

@interface ICMAppointmentRepairPartsTableViewCell ()

@property (nonatomic, strong) UILabel *operateLabel;

@property (nonatomic, strong) UILabel *orderLabel;

@property (nonatomic, strong) UILabel *partNumberLabel;

@property (nonatomic, strong) UILabel *partNameLabel;

@property (nonatomic, strong) UITextField *quantityTextField;

@property (nonatomic, strong) UILabel *unitPriceLabel;

@property (nonatomic, strong) UILabel *totalPriceLabel;

@property (nonatomic, strong) UILabel *repairTypeLabel;

@property (nonatomic, strong) UILabel *stockPlaceLabel;

@property (nonatomic, strong) UILabel *partPropertyLabel;
@end

@implementation ICMAppointmentRepairPartsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
#pragma mark    初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *repairPartsCellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-ActualWidth(20), ActualHeight(25))];
        repairPartsCellView.backgroundColor = BackgroundColor_Gray;
        [self.contentView addSubview:repairPartsCellView];
        
        UILabel *operateLabel = [self createLabelWithText:@"❌" frame:CGRectMake(0, ActualHeight(5), ActualWidth(50), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:operateLabel];
        self.operateLabel = operateLabel;
        
        UIView *firstSep = [[UIView alloc] initWithFrame:CGRectMake(operateLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        firstSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:firstSep];
        
        UILabel *orderLabel = [self createLabelWithText:@"1" frame:CGRectMake(firstSep.rightEdge, operateLabel.y, ActualWidth(50), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:orderLabel];
        self.orderLabel = orderLabel;
        
        UIView *secondSep = [[UIView alloc] initWithFrame:CGRectMake(orderLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        secondSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:secondSep];
        
        UILabel *partNumberLabel = [self createLabelWithText:@"" frame:CGRectMake(secondSep.rightEdge, operateLabel.y, ActualWidth(145), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:partNumberLabel];
        self.partNumberLabel = partNumberLabel;
        
        UIView *thirdSep = [[UIView alloc] initWithFrame:CGRectMake(partNumberLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        thirdSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:thirdSep];
        
        UILabel *partNameLabel = [self createLabelWithText:@"" frame:CGRectMake(thirdSep.rightEdge, operateLabel.y, ActualWidth(235), ActualHeight(15)) textAlignment:NSTextAlignmentLeft];
        [repairPartsCellView addSubview:partNameLabel];
        self.partNameLabel = partNameLabel;
        
        UIView *fourthSep = [[UIView alloc] initWithFrame:CGRectMake(partNameLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        fourthSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:fourthSep];
        
        UITextField *quantityTextField = [[UITextField alloc] initWithFrame:CGRectMake(fourthSep.rightEdge, operateLabel.y, ActualWidth(75), ActualHeight(15))];
        quantityTextField.font = ContentFont;
        quantityTextField.textColor = ContentTextColor_Black;
        quantityTextField.textAlignment = NSTextAlignmentRight;
        [repairPartsCellView addSubview:quantityTextField];
        self.quantityTextField = quantityTextField;
        
        UIView *fifthSep = [[UIView alloc] initWithFrame:CGRectMake(quantityTextField.rightEdge, 0, 1, repairPartsCellView.height)];
        fifthSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:fifthSep];
        
        UILabel *unitPriceLabel = [self createLabelWithText:@"" frame:CGRectMake(fifthSep.rightEdge, operateLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [repairPartsCellView addSubview:unitPriceLabel];
        self.unitPriceLabel = unitPriceLabel;
        
        UIView *sixthSep = [[UIView alloc] initWithFrame:CGRectMake(unitPriceLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        sixthSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:sixthSep];
        
        UILabel *totalPriceLabel = [self createLabelWithText:@"" frame:CGRectMake(sixthSep.rightEdge, operateLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [repairPartsCellView addSubview:totalPriceLabel];
        self.totalPriceLabel = totalPriceLabel;
        
        UIView *seventhSep = [[UIView alloc] initWithFrame:CGRectMake(totalPriceLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        seventhSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:seventhSep];
        
        UILabel *repairTypeLabel = [self createLabelWithText:@"" frame:CGRectMake(seventhSep.rightEdge, operateLabel.y, ActualWidth(75), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:repairTypeLabel];
        self.repairTypeLabel = repairTypeLabel;
        
        UIView *eighthSep = [[UIView alloc] initWithFrame:CGRectMake(repairTypeLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        eighthSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:eighthSep];
        
        UILabel *stockPlaceLabel = [self createLabelWithText:@"" frame:CGRectMake(eighthSep.rightEdge, operateLabel.y, ActualWidth(125), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:stockPlaceLabel];
        self.stockPlaceLabel = stockPlaceLabel;
        
        UIView *ninthSep = [[UIView alloc] initWithFrame:CGRectMake(stockPlaceLabel.rightEdge, 0, 1, repairPartsCellView.height)];
        ninthSep.backgroundColor = BorderColor_Gray;
        [repairPartsCellView addSubview:ninthSep];
        
        UILabel *partPropertyLabel = [self createLabelWithText:@"" frame:CGRectMake(ninthSep.rightEdge, operateLabel.y, ScreenWidth-ActualWidth(40)-stockPlaceLabel.rightEdge, ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [repairPartsCellView addSubview:partPropertyLabel];
        self.partPropertyLabel = partPropertyLabel;
    }
    return self;
}
#pragma mark    根据model设置界面
- (void)setupLabelsWithModel:(ICMAppointmentPartsModel *)model{
    self.partNumberLabel.text = model.partNumber;
    self.partNameLabel.text = model.partName;
    self.quantityTextField.text = [NSString stringWithFormat:@"%.2f",[model.quantity floatValue]];
    self.unitPriceLabel.text = [NSString stringWithFormat:@"%.2f",[model.unitPrice floatValue]];
    self.totalPriceLabel.text = [NSString stringWithFormat:@"%.2f",[model.totalPrice floatValue]];
    self.repairTypeLabel.text = model.type;
    self.stockPlaceLabel.text = model.stockPlace;
    self.partPropertyLabel.text = model.partProperty;
}

- (UILabel *)createLabelWithText:(NSString *)text frame:(CGRect)frame textAlignment:(NSTextAlignment)textAlignment{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = ContentFont;
    label.textColor = ContentTextColor_Black;
    label.textAlignment = textAlignment;
    return label;
}

@end
